/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */

package com.ykht.proj.activity.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ykht.proj.activity.vo.VActivityCardVo;
import com.ykht.proj.common.core.util.R;
import com.ykht.proj.common.log.annotation.SysLog;
import com.ykht.proj.activity.entity.VActivityCard;
import com.ykht.proj.activity.service.VActivityCardService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 活动和卡表关联表
 *
 * @author csg
 * @date 2021-05-21 14:20:15
 */
@RestController
@AllArgsConstructor
@RequestMapping("/vactivitycard" )
@Api(value = "vactivitycard", tags = "活动和卡表关联表管理")
public class VActivityCardController {

    private final  VActivityCardService vActivityCardService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param vActivityCard 活动和卡表关联表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('activity_vactivitycard_view')" )
    public R getVActivityCardPage(Page page, VActivityCard vActivityCard) {
        return R.ok(vActivityCardService.page(page, Wrappers.query(vActivityCard)));
    }


    /**
     * 通过id查询活动和卡表关联表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('activity_vactivitycard_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(vActivityCardService.getById(id));
    }

    /**
     * 新增活动和卡表关联表
     * @param vActivityCard 活动和卡表关联表
     * @return R
     */
    @ApiOperation(value = "新增活动和卡表关联表", notes = "新增活动和卡表关联表")
    @SysLog("新增活动和卡表关联表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('activity_vactivitycard_add')" )
    public R save(@RequestBody VActivityCard vActivityCard) {
        return R.ok(vActivityCardService.save(vActivityCard));
    }

    /**
     * 修改活动和卡表关联表
     * @param vActivityCard 活动和卡表关联表
     * @return R
     */
    @ApiOperation(value = "修改活动和卡表关联表", notes = "修改活动和卡表关联表")
    @SysLog("修改活动和卡表关联表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('activity_vactivitycard_edit')" )
    public R updateById(@RequestBody VActivityCard vActivityCard) {
        return R.ok(vActivityCardService.updateById(vActivityCard));
    }

    /**
     * 通过id删除活动和卡表关联表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除活动和卡表关联表", notes = "通过id删除活动和卡表关联表")
    @SysLog("通过id删除活动和卡表关联表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('activity_vactivitycard_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(vActivityCardService.removeById(id));
    }



	/**
	 * 根据活动id查询 活动和卡表关联表数据
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "根据活动id查询 活动和卡表关联表数据", notes = "根据活动id查询 活动和卡表关联表数据")
	@GetMapping("/getByActivityId" )
	public R<IPage<VActivityCardVo>> getByActivityId(Page page, Long id) {
		return R.ok(vActivityCardService.getByActivityId(page, id));
	}

}
